<template>
    <div class="my-auto">
        <button @click="des" class="mx-2" style="background:#F2F3F5;border:0;width:30px;height:30px;">-</button>
        <input :value="value" @input="changeing" style="width: 60px;border:0px;height:30px;text-align:center;background:#F2F3F5;" type="text">
        <button style="background:#F2F3F5;border:0;width:30px;height:30px;" @click="add" class="mx-2">+</button>
    </div>
</template>

<script>
export default {
    name:'countNum',
    methods:{
        changeing() {
            if(+this.num <= 0 || isNaN(this.num))return this.num = 1
        },
        add(){
            this.num++
            this.$emit('input',this.num)
        },
        des(){
            this.num === 1 ? this.num : this.num--
            this.$emit('input',this.num)
        }
    },
    props:['value'],
    data(){
        return{
            num:this.value
        }
    }
}
</script>

<style scoped lang="less">
@import url('@/style/bootstrap.css');
div{
    display: flex;
    flex-wrap: nowrap;
}
</style>